<?php
namespace app\home\controller;

use think\Controller;
use think\facade\Request;
use think\facade\Session;
use app\home\model\User;

class Index extends Base
{
    public function index()
    {
        return view('index');
    }
	public function user(){
		$this->view->engine->layout(false);
		return view('user');
	}
	public function upload(){
		$file=request()->file('figure_url');
		$info=$file->move('../public/upload');
		if($info){
			$figure_url="/upload/".$info->getSaveName();
			return $figure_url;
		}else{
			$this->error('文件上传失败');
		}
	}
	public function useredit(){
		$param=input();
		// dump($param);
		$url=$this->upload();
		// dump($url);
		$data=['figure_url'=>$url,'username'=>$param['username'],'phone'=>$param['phone'],'email'=>$param['email']];
		User::where('id',$param['id'])->update($data);
		$res=User::where('id',$param['id'])->find();
		if($res){
			session('user_info',$res->toArray());
			$this->redirect('index/user');
		}else{
			$this->error('修改失败');
		}
	}
}
